Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile of Go plugin or shared library for Linux ARM64 #129

Closed
wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 27, 2023

Cross compile a Go plugin for Linux ARM64 requires the command $CC -fuse-ld=gold -Wl,--version, executed by the Go toolchain, return the string GNU gold.

Using Go 1.20.4:

link: ARM external linker must be gold (issue #15696), but is not: zig ld 0.11.0

Using Go 1.21.3:

link: ARM64 external linker must be gold (issue #15696, 22040), but is not: zig ld 0.11.0

Building a Go plugin library force the Go toolchain to pass in the code src/cmd/link/internal/ld/lib.go to link the binary.

See https://go.dev/issue/15696 and https://go.dev/issue/22040 for more details.

Fixes #122

@CLAassistant
Copy link

CLAassistant commented Oct 27, 2023

CLA assistant check
All committers have signed the CLA.

test/plugin/BUILD Outdated Show resolved Hide resolved
Add test to try to cross compile a Go plugin for Linux ARM64,
requiring the command `$CC -fuse-ld=gold -Wl,--version`, executed
by the Go toolchain, to return the string `GNU gold`.

Using Go *1.20.4*:

```
link: ARM external linker must be gold (issue #15696), but is not: zig ld 0.11.0
```

Using Go *1.21.3*:

```
link: ARM64 external linker must be gold (issue #15696, 22040), but is not: zig ld 0.11.0
```

Building a Go `plugin` library force the Go toolchain
to pass in the code [1] to link the binary.
Enable CGO and cross compile (GOOS=linux GOARCH=arm64) is not
sufficient.

See https://go.dev/issue/15696 and https://go.dev/issue/22040 for more
details.

Issue: #122

[1]: https://go.googlesource.com/go/+/8c92897e15d15fbc664cd5a05132ce800cf4017f/src/cmd/link/internal/ld/lib.go#1628
@ghost ghost changed the title tests: add test on Go binary for Linux ARM64 tests: add test for the build of a Go plugin for Linux ARM64 Oct 27, 2023
@ghost ghost changed the title tests: add test for the build of a Go plugin for Linux ARM64 Fix compile of Go plugin or shared library for Linux ARM64 Oct 27, 2023
@ghost ghost marked this pull request as ready for review October 27, 2023 21:20
@motiejus
Copy link
Collaborator

motiejus commented Oct 28, 2023

Thank you for filing this.

Cross compile a Go plugin for Linux ARM64 requires the command $CC -fuse-ld=gold -Wl,--version, executed by the Go toolchain, return the string GNU gold.

This is the main culprit. In this case, go should also accept zig ld as a valid linker instead of Zig pretending to be gold. Go is quite OK with having such zig-specific patches where they try to differentiate between linkers/compilerrs (see my past PRs in Go). From the cursory look, the patch to Go should be relatively straightforward. Fix in Go will also fix everyone using Zig for building Go plugins outside of hermetic_cc_toolchain.

I will accept this particular PR as a temporary measure once there is a proper fix merged to Go. Then we can delete it after the next Go major version gets released.

@ghost
Copy link
Author

ghost commented Oct 29, 2023

Yes, I totaly agree, the fix should be done in Go. I didn't know a PR in Go was in progress.
Considering this is very specific to the Go version used, and a fix in Go could be arrived in the next release of Go, I think we (hermetic_cc_toolchain users) should use a little patch file rather than to commit this PR.

@motiejus
Copy link
Collaborator

motiejus commented Oct 29, 2023

Sorry, there is no PR in progress in Go. I meant Go is OK with zig-specific patches, and I suggested looking into my PRs for examples (almost all are zig specific IIRC).

@ghost ghost closed this Apr 26, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ARM external linker must be gold (issue #15696), but is not: zig ld 0.11.0
3 participants